from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-11 14:05:35.883076
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 11, May, 2021
Time: 14:05:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1447
Nobs: 288.000 HQIC: -48.8307
Log likelihood: 3509.78 FPE: 3.92651e-22
AIC: -49.2894 Det(Omega_mle): 2.88797e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.380673 0.114462 3.326 0.001
L1.Burgenland 0.073589 0.058815 1.251 0.211
L1.Kärnten -0.225761 0.052359 -4.312 0.000
L1.Niederösterreich 0.106155 0.125031 0.849 0.396
L1.Oberösterreich 0.218253 0.122174 1.786 0.074
L1.Salzburg 0.280176 0.067035 4.180 0.000
L1.Steiermark 0.109776 0.085731 1.280 0.200
L1.Tirol 0.118770 0.059332 2.002 0.045
L1.Vorarlberg -0.031188 0.054585 -0.571 0.568
L1.Wien -0.022839 0.108885 -0.210 0.834
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.407307 0.131866 3.089 0.002
L1.Burgenland 0.006221 0.067758 0.092 0.927
L1.Kärnten 0.328097 0.060320 5.439 0.000
L1.Niederösterreich 0.121097 0.144042 0.841 0.401
L1.Oberösterreich -0.069206 0.140751 -0.492 0.623
L1.Salzburg 0.231591 0.077227 2.999 0.003
L1.Steiermark 0.089455 0.098766 0.906 0.365
L1.Tirol 0.135664 0.068354 1.985 0.047
L1.Vorarlberg 0.153234 0.062885 2.437 0.015
L1.Wien -0.395165 0.125441 -3.150 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254284 0.058368 4.357 0.000
L1.Burgenland 0.105502 0.029992 3.518 0.000
L1.Kärnten -0.012678 0.026700 -0.475 0.635
L1.Niederösterreich 0.092180 0.063757 1.446 0.148
L1.Oberösterreich 0.283834 0.062301 4.556 0.000
L1.Salzburg 0.019278 0.034183 0.564 0.573
L1.Steiermark -0.001742 0.043717 -0.040 0.968
L1.Tirol 0.069771 0.030255 2.306 0.021
L1.Vorarlberg 0.077312 0.027835 2.778 0.005
L1.Wien 0.113956 0.055524 2.052 0.040
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197866 0.055517 3.564 0.000
L1.Burgenland 0.028868 0.028527 1.012 0.312
L1.Kärnten 0.009475 0.025395 0.373 0.709
L1.Niederösterreich 0.061635 0.060643 1.016 0.309
L1.Oberösterreich 0.394589 0.059257 6.659 0.000
L1.Salzburg 0.082687 0.032513 2.543 0.011
L1.Steiermark 0.129993 0.041581 3.126 0.002
L1.Tirol 0.051094 0.028777 1.775 0.076
L1.Vorarlberg 0.082655 0.026475 3.122 0.002
L1.Wien -0.040017 0.052812 -0.758 0.449
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.421633 0.109296 3.858 0.000
L1.Burgenland 0.104718 0.056160 1.865 0.062
L1.Kärnten 0.011108 0.049996 0.222 0.824
L1.Niederösterreich 0.045010 0.119388 0.377 0.706
L1.Oberösterreich 0.117986 0.116660 1.011 0.312
L1.Salzburg 0.061421 0.064009 0.960 0.337
L1.Steiermark 0.061235 0.081861 0.748 0.454
L1.Tirol 0.197025 0.056654 3.478 0.001
L1.Vorarlberg 0.040309 0.052121 0.773 0.439
L1.Wien -0.056113 0.103970 -0.540 0.589
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215398 0.085503 2.519 0.012
L1.Burgenland -0.012624 0.043935 -0.287 0.774
L1.Kärnten -0.005406 0.039112 -0.138 0.890
L1.Niederösterreich -0.005989 0.093398 -0.064 0.949
L1.Oberösterreich 0.415328 0.091264 4.551 0.000
L1.Salzburg 0.011558 0.050075 0.231 0.817
L1.Steiermark -0.030710 0.064040 -0.480 0.632
L1.Tirol 0.161380 0.044321 3.641 0.000
L1.Vorarlberg 0.058728 0.040775 1.440 0.150
L1.Wien 0.198199 0.081337 2.437 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188204 0.104805 1.796 0.073
L1.Burgenland 0.023124 0.053853 0.429 0.668
L1.Kärnten -0.070699 0.047942 -1.475 0.140
L1.Niederösterreich -0.030343 0.114482 -0.265 0.791
L1.Oberösterreich 0.010574 0.111866 0.095 0.925
L1.Salzburg 0.090173 0.061379 1.469 0.142
L1.Steiermark 0.314062 0.078497 4.001 0.000
L1.Tirol 0.455715 0.054326 8.388 0.000
L1.Vorarlberg 0.149452 0.049980 2.990 0.003
L1.Wien -0.128512 0.099698 -1.289 0.197
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199795 0.123939 1.612 0.107
L1.Burgenland 0.041476 0.063685 0.651 0.515
L1.Kärnten -0.073639 0.056694 -1.299 0.194
L1.Niederösterreich 0.114953 0.135383 0.849 0.396
L1.Oberösterreich 0.015034 0.132289 0.114 0.910
L1.Salzburg 0.194015 0.072585 2.673 0.008
L1.Steiermark 0.130727 0.092828 1.408 0.159
L1.Tirol 0.055766 0.064244 0.868 0.385
L1.Vorarlberg 0.107752 0.059104 1.823 0.068
L1.Wien 0.221749 0.117900 1.881 0.060
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487331 0.069355 7.027 0.000
L1.Burgenland -0.011680 0.035637 -0.328 0.743
L1.Kärnten -0.017779 0.031725 -0.560 0.575
L1.Niederösterreich 0.110828 0.075759 1.463 0.143
L1.Oberösterreich 0.303516 0.074028 4.100 0.000
L1.Salzburg 0.025098 0.040618 0.618 0.537
L1.Steiermark -0.046229 0.051946 -0.890 0.373
L1.Tirol 0.079420 0.035951 2.209 0.027
L1.Vorarlberg 0.104239 0.033074 3.152 0.002
L1.Wien -0.032556 0.065976 -0.493 0.622
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.164383 0.087007 0.169783 0.222524 0.076576 0.090404 0.000834 0.169905
Kärnten 0.164383 1.000000 0.053293 0.214534 0.188121 -0.066538 0.179292 0.022162 0.309388
Niederösterreich 0.087007 0.053293 1.000000 0.241750 0.097503 0.315306 0.145928 0.026803 0.311347
Oberösterreich 0.169783 0.214534 0.241750 1.000000 0.304045 0.261547 0.107627 0.062856 0.143502
Salzburg 0.222524 0.188121 0.097503 0.304045 1.000000 0.150711 0.078941 0.091511 0.033772
Steiermark 0.076576 -0.066538 0.315306 0.261547 0.150711 1.000000 0.097143 0.100751 -0.101106
Tirol 0.090404 0.179292 0.145928 0.107627 0.078941 0.097143 1.000000 0.153775 0.159330
Vorarlberg 0.000834 0.022162 0.026803 0.062856 0.091511 0.100751 0.153775 1.000000 -0.010727
Wien 0.169905 0.309388 0.311347 0.143502 0.033772 -0.101106 0.159330 -0.010727 1.000000